
package com.hd2.controlhd.banco;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Dulcyelliton
 */
public class acessoBD {

    private String DRIVER = "com.mysql.jdbc.Driver";
    private String DATABASE = "base_nfehd2";
    private String SERVIDOR = "localhost:3306/"+DATABASE;
    //private String SERVIDOR = "201.20.20.230:3306/"+DATABASE;
    private String USER = "root";
    private String PASSWORD = "root";
    private static acessoBD instance;
    private static final Logger log = Logger.getLogger(acessoBD.class.getName());
    public static Connection con = null;
    
     public void Banco() {
        Conectar();
    }
    
    public void Conectar(){
         System.out.println("Realizando Conexão ao Banco de Dados...");
        try {
            Class.forName(DRIVER);
            con = DriverManager.getConnection("jdbc:mysql://"+SERVIDOR, USER, PASSWORD);
            System.out.println("Banco: Conectado !");
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(acessoBD.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException e) {
            System.out.println(e);
            throw new RuntimeException(e);
        }
    }
    
    
    public void Desconectar(){
        try {
            con.close();
            System.out.println("Banco: Desconectado !");
        } catch (SQLException ex) {
            Logger.getLogger(acessoBD.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public Connection getConection(){
        return acessoBD.con;
    } 
    
    public static acessoBD getInstance(){
        if(instance == null){
            instance = new acessoBD();
        }
        return instance;
    }
    
    public static void kilInstance(){
        instance = null;
    }
    
}
